﻿namespace ChessToys
{
    using System;

    /// <summary>
    /// Utilities for <see cref="IPiece"/>.
    /// </summary>
    public static class PieceUtils
    {
        /// <summary>
        /// Determines whether the given piece has specific type.
        /// </summary>
        /// <param name="piece">The piece.</param>
        /// <param name="type">The type.</param>
        /// <returns>
        /// 	<c>true</c> if the piece has the expected type; otherwise, <c>false</c>.
        /// </returns>
        public static bool Is(IPiece piece, Type type)
        {
            if (piece == null || type == null)
            {
                return false;
            }
            return piece.GetType() == type;
        }

        /// <summary>
        /// Determines whether the given piece has specific type and color.
        /// </summary>
        /// <param name="piece">The piece.</param>
        /// <param name="type">The type.</param>
        /// <param name="color">The color</param>
        /// <returns>
        /// 	<c>true</c> if the piece has the expected type and color; otherwise, <c>false</c>.
        /// </returns>
        public static bool Is(IPiece piece, Type type, Color color)
        {
            return Is(piece, type) && piece.Color == color;
        }
    }
}
